<template>
  <div class="container" >
   <template v-if="detailStatus==false">
    <img src="@/assets/img/jxgg.png" alt />
   
   <div class="list">
     <div class="card" v-for="(item,index) in newsList" :key="index" @click="toDetail(item.id)">
      <img :src="item.picture" alt="">
       <div class="content">
         <div class="title">{{item.title}}</div>
         <div
           class="news"
         >{{item.introduction}}</div>
         <div class="btn">新闻动态</div>
       </div>

     </div>
     <el-pagination class="fenye"
     @size-change="handleSizeChange"
     @current-change="handleCurrentChange"
     :page-sizes="[4,6,8]"
     :page-size="100"
     layout="total, sizes, prev, pager, next, jumper"
     :total="total"
   ></el-pagination>
   
   </div>
   </template>
   
   <template v-if="detailStatus==true">
    <img src="@/assets/img/jxgg.png" alt />
    <div class="detail">
      <div class="top">
        <div class="title">
          {{info.title}}
        </div>
        <div class="time">发布时间:{{info.addtime}}</div>
      </div>
      <div class="content" v-html="info.content">
        
      </div>

      <div class="back">
        <el-button type="primary" style="margin-right:10px;" @click="detailStatus = false"> <i class="el-icon-back"></i>返回新闻列表 </el-button>
      </div>
    </div>
   </template>
   
  </div>
</template>

<script>
import {newsList,newsInfo} from '@/api/news'

export default {
  name: "News",
  data() {
    return {
      type: "",
      total: 0,
      detailStatus:false,
      newsList: [],
      pageNumber: 1, //当前页
      pagesize: 4 ,//分页的数据
      info:{}
    };
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      this.getNewsList()
    },
    handleCurrentChange(val) {
      this.pageNumber = val;
      this.getNewsList()
    },
    async getNewsList() {
      let res = await newsList({
        pagesize: this.pagesize,
        pageNumber: this.pageNumber,
      });
      
      if (res.code == 200) {
       
        this.newsList = res.data;
        this.newsList.forEach(item => {
            item.addtime = this.dayjs(item.addtime).format("YYYY-MM-DD HH:mm:ss")
        });
        this.total = res.totalCount;
      }
    },
   async toDetail(id){
      this.detailStatus = true
      let res =await newsInfo(id)
      if(res.code==200){
      this.info = res.data
      this.info.addtime = this.dayjs( this.info.addtime).format("YYYY-MM-DD HH:mm:ss")
    }
    }

  
  },
  mounted() {
    this.getNewsList()
  },
};
</script>

<style scoped lang="scss">

.container {
  width: 87%;
  box-shadow: 4px 4px 15px rgb(136, 116, 116);
  margin-left: 40px;
  padding: 20px 0;
  box-sizing: border-box;
.detail{
  width: 100%;
  box-sizing: border-box;
 .top{
  width: 100%;
  height: 200px;
  padding-top: 50px;
  text-align: center;
 
  border-bottom: 1px solid black;
  .title{
    font-size: 28px;
  }
  .time{
    font-size: 14px;
    margin-top: 100px;
  }
 }
 .content{
  padding: 30px;
  
 }
 .back{
  width: 95%;
  margin-left: 2%;
  border-radius: 5px;
  height: 60px;
  background-color: #757e87;
  display: flex;
  align-items: center;
  padding-left: 82%;
  
 }
}
  img {
    width: 100%;
  }
  
  .list {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    padding: 20px 20px;
    width: 100%;
    box-sizing: border-box;
   
    position: relative;
    .fenye{
      position: absolute;
      left: 30%;
      bottom: -20px;

    }
    .card {
      width: 500px;
      height: 200px;
      box-shadow: 4px 4px 15px rgb(136, 116, 116);
      display: flex;
      align-items: center;
      padding-left: 10px;
      margin-top: 15px;
      img {
        height: 80%;
        width: 40%;
      }
      .content {
        height: 80%;
        width: 60%;
        padding-left: 10px;
        .title {
          width: 100%;
          height: 20px;
          font-size: 18px;
          overflow: hidden;
        }
        .news {
          margin: 10px 0px;
          overflow: hidden;
          text-align: left;
          color: rgb(51, 51, 51);
          font-size: 14px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 3;
          line-height: 32px;
        }
        .btn{
          width: 60px;
          height: 20px;
          font-size: 12px;
          text-align: center;
          line-height: 20px;
          color: #fff;
          background-color: rgb(79, 170, 212);
          border-radius: 5px;
        }
     
      }
    }
  }
}
</style>